package com.shelpe.services.sinbad.entity.jpa;

import java.util.Date;

import javax.persistence.AttributeConverter;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import com.shelpe.services.sinbad.entity.jpa.CampaignLog.Action;
import com.shelpe.services.sinbad.entity.jpa.CampaignLog.ActionConverter;

import lombok.Data;
@Entity(name = "keywords_log")
@Data
public class KeywordsLog {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private long logID;
	@Column(name = "keyword_id")
	private long keywordID;
	@Column(name = "adgroup_id")
	private long adgroupID;
	@Convert(converter = ActionConverter.class)
	private Action action;

	private int newIntVal;

	private Date updatedTime;

	private String keyword;

	private String note;

	public static enum Action {
		AUTO_NEW_KEYWORD(0), // 自动加词
		AUTO_CHANGE_PRICE(1), // 自动改价
		AUTO_DEL_KEYWORD(2), // 自动删词
		AUTO_CHANGE_MATCHSCOPE(3), // 自动修改匹配方式
		SEMIAUTO_EXEC_UPDATE(4), // 思路执行-调价
		SEMIAUTO_EXEC_DEL(5), //思路执行-删除
		MANUAL_NEW_KEYWORD(10), // 手动加词
		MANUAL_CHANGE_PRICE(11), // 手动改价
		MANUAL_DEL_KEYWORD(12), // 手动删词
		MANUAL_CHANGE_MATCHSCOPE(13); // 手动修改匹配方式

		private int value;

		private Action(int v) {
			this.value = v;
		}

		public int getValue() {
			return this.value;
		}

		public String toDisplay() {
			return this.name().toLowerCase();
		}
	}
	public static class ActionConverter implements AttributeConverter<Action, Integer> {

		@Override
		public Integer convertToDatabaseColumn(Action attribute) {
			return attribute.value;
		}

		@Override
		public Action convertToEntityAttribute(Integer dbData) {
			Action action = null;
			Action.values();
			for (Action a : Action.values()) {
				if (a.getValue() == dbData) {
					action = a;
					break;
				}
			}
			return action;
		}
	}
}
